
#include <iostream>
#include <vector>
#include <algorithm>		// 	find / sort

using namespace std;

class Student{
public:
	Student(string const& name="", int age=0) : m_name(name), m_age(age){}
	bool operator==(Student const& that) const {
		return m_name == that.m_name && m_age == that.m_age;
	}
	bool operator<(Student const& that) const {
		return m_age < that.m_age;
	}
	bool operator>(Student const& that) const {
		return m_age > that.m_age;
	}
private:
	string m_name;
	int m_age;
	friend ostream& operator<<(ostream& os, Student const& stu);
};

ostream& operator<<(ostream& os, Student const& stu){
	return os << stu.m_name << " : " << stu.m_age;
}

void print(string const& str, vector<Student>& v){
	cout << str << endl;
	/*
	typedef vector<Student>::iterator IT;
	for(IT it=v.begin(); it!=v.end(); ++it){
		cout << *it << endl;
	}
	*/
	/*
	for(auto const& i : v)
		cout << i << endl;
	*/
	for(int i = 0; i < v.size(); ++i)
		cout << v[i] << endl;
	cout << "-----------------------------" << endl;
}

int main(){
	vector<Student> v;
	v.reserve(10);
	v.push_back(Student("zhangsan", 22));
	v.push_back(Student("lisi", 21));
	v.push_back(Student("maliu", 40));
	v.push_back(Student("yufengguang", 18));
	v.push_back(Student("tianqi", 24));
	print("After : ", v);

	v.insert(++v.begin(), Student("zhaoliying", 100));
	print("Insert : ", v);

	v.erase(v.begin());
	print("Erase : ", v);

	typedef vector<Student>::iterator IT;
	IT it = ++v.begin();
	*it = Student("liyuanfang", 66);
	print("Modify : ", v);

	IT fit = find(v.begin(), v.end(), Student("maliu", 40));
	if(fit != v.end()){
		v.erase(fit);
		print("Find it and delete : ", v);
	}
	else
		cout << "Not Find" << "---------------------" << endl;

//	sort(v.begin(), v.end());
	sort(v.begin(), v.end(), greater<Student>());	// reverse
	print("sort : ", v);

	return 0;
}
